﻿using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class DelFarmCommmandHander : IRequestHandler<DelFarmCommmand, ApiResult<object>>
    {
        public readonly IRepistory<Farm> _farmRepository;
        public DelFarmCommmandHander(IRepistory<Farm> farmRepository)
        {
            _farmRepository = farmRepository;
        }
        public Task<ApiResult<object>> Handle(DelFarmCommmand request, CancellationToken cancellationToken)
        {
           ApiResult<object> apiResult = new ApiResult<object>();
           var  result=_farmRepository.GetAll().Where(x=>x.FarmId==request.FarmId).FirstOrDefault();
           _farmRepository.Delete(result);
           apiResult.Data = null;
           apiResult.code = Renum.删除成功;
           apiResult.Message = Renum.删除失败.ToString();
           return Task.FromResult(apiResult);
        }
    }
}
